﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using Kingdee.BOS.App.Data;
using System.Data;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Metadata;
namespace LiMinCRMPlugin
{
    /// <summary>
    /// 预计出表单插件      
    /// mey
    /// 2024年6月19日
    /// </summary>
    [System.ComponentModel.Description("预计出表单插件")]
    [HotUpdate]
    public class OutboundQuantityForm : AbstractBillPlugIn
    {
        public override void ButtonClick(ButtonClickEventArgs e)
        {
            base.ButtonClick(e);
        }

        public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
        {
            base.EntityRowDoubleClick(e);
            string OutFid = "";
            if (e.Row >= 0)
            {
                OutFid = this.View.Model.GetValue("F_QLTK_PoOrder", e.Row).ToString();
                if (OutFid != "")
                {
                    string Ftype = this.View.Model.GetValue("F_QLTK_BillName", e.Row).ToString();
                    if (Ftype == "销售订单")
                    {
                        string sql = @"/*dialect*/  select fid from T_SAL_ORDER where FBillNo='" + OutFid + "'";
                        DataTable dt_UR = DBUtils.ExecuteDataSet(Context, sql).Tables[0];
                        if (dt_UR != null && dt_UR.Rows.Count > 0)
                        {
                            //以单据视图打开
                            BillShowParameter para = new BillShowParameter();
                            //para.OpenStyle.ShowType = ShowType.Modal;
                            //采购订单唯一标识
                            para.FormId = "SAL_SaleOrder";
                            //样式 view 查看
                            para.Status = OperationStatus.VIEW;
                            //要打开单据的FID
                            para.PKey = dt_UR.Rows[0][0].ToString();
                            //para.ParentPageId = this.View.ParentFormView.PageId;
                            this.View.ShowForm(para);
                        }

                    }
                    else if (Ftype == "发货通知单")
                    {
                        string sql = @"/*dialect*/  select fid from T_SAL_DELIVERYNOTICE where FBillNo='" + OutFid + "'";
                        DataTable dt_UR = DBUtils.ExecuteDataSet(Context, sql).Tables[0];
                        if (dt_UR != null && dt_UR.Rows.Count > 0)
                        {
                            //以单据视图打开
                            BillShowParameter para = new BillShowParameter();
                            //para.OpenStyle.ShowType = ShowType.Modal;
                            //采购订单唯一标识
                            para.FormId = "SAL_DELIVERYNOTICE";
                            //样式 view 查看
                            para.Status = OperationStatus.VIEW;
                            //要打开单据的FID
                            para.PKey = dt_UR.Rows[0][0].ToString();
                            //para.ParentPageId = this.View.ParentFormView.PageId;
                            this.View.ShowForm(para);
                        }
                    }


                }
            }
        }

    }
}
